let login = async (username, password) => {
    let formData = new FormData();
    formData.append('username', username)
    formData.append('password', password)

    let res = await fetch(' http://10.204.39.236:8080/auth/login', {
        body: formData,
        method: "POST"
    })
    return await res.text()
}

let getProfile = async (token) => {
    let profile = await fetch(` http://10.204.39.236:8080/auth/?token=${token}`, {
        method: "GET"
    })
    return await profile.json()
}

let rent = async (seat_id, token) => {
    let formData = new FormData();
    formData.append('seat_id', seat_id)
    formData.append('token', token)

    let res = await fetch(' http://10.204.39.236:8080/seat/rent', {
        body: formData,
        method: "POST"
    })
    return await res.text()
}

let giveBack = async (machine_id, token, totp) => {
    let formData = new FormData();
    formData.append('machine_id', machine_id)
    formData.append('token', token)
    formData.append('totp', totp)

    return await fetch(' http://10.204.39.236:8080/seat/give_back', {
        body: formData,
        method: "POST"
    })
}

let getTickets = async (token) => {
    let res = await fetch(` http://10.204.39.236:8080/ticket/?token=${token}`, {
        method: "GET"
    })
    return await res.json()
}

export {login, getProfile, rent, giveBack, getTickets}